<template>
	<view class="sbody">
		<!-- 头部信息 -->
		<view class="top">
			<view class="textStyle" style="justify-content: flex-end;line-height: 140rpx;color: white;padding: 0 5%;" >
				<!-- <span style="font-size: 50rpx;font-weight: 500;font-family:PingFang SC;" >去登录
					<span class="iconfont" style="font-size: 50rpx;">&#xe65e;</span>
				</span> -->
				<span style="font-weight: 100;" @click="goToContact"><span class="iconfont"
						style="position:relative; right: 10rpx;bottom: -5rpx;">&#xe63c;</span>联系客服</span>
			</view>
			<!-- 二维码等信息 -->
			<view class="boxbody">
				<view class="textStyle">
					<view class="image-box" v-for="(item,index) in imageBoxList" :key="index">
						<image :src="'http://101.206.123.213:7051/static/image/index/'+item+'@2x.png'" class="box-image"
							@click="navigaterTo(item)" />
						<view style="font-weight: bold;">{{item}}</view>
					</view>
				</view>
			</view>
			<!-- 访客登记等信息 -->
			<view class="textStyle boxbottom">
				<view class="image-box-bottom" v-for="(item,index) in imageBoxBottomList" :key="index">
					<image :src="'http://101.206.123.213:7051/static/image/index/'+item+'@2x.png'" class="box-image"
						@click="navigaterTo(item)" />
					<view>{{item}}</view>
				</view>
			</view>
		</view>
		<!-- 消息通知轮播图 -->
		<view class="notice">
			<view class="notice-img"></view>
			<view class="notice-title">
				<text style="float: left;margin-top:23rpx;width: 40rpx;" @click="navigaterTo('通知公告')">通知公告</text>
			</view>
			<view class="notic-message" style="overflow: hidden;">
				<swiper style="width: 100%;overflow: hidden;" vertical="true" autoplay="true" interval="5000">
					<swiper-item v-for="(item, index) in noticeList" :key=index>
						<scroll-view scroll-y="true">
							<view>{{item}}</view>
						</scroll-view>
					</swiper-item>
				</swiper>
			</view>
		</view>
		<!-- banner轮播图 -->
		<view class="slides">
			<swiper class="slides" indicator-active-color="rgb(255,255,255)" autoplay="true" interval="5000"
				indicator-dots="true">
				<swiper-item v-for="(item,index) in advertisementList" :key=index>
					<scroll-view scroll-x="true">
						<image class="slides" :src="item.imgSrc" @click="imgClick(item)"
							style="background-repeat: no-repeat;background-size: cover;">
					</scroll-view>
				</swiper-item>
			</swiper>

			</image>
		</view>
		<!-- 资讯/招商 -->
		<view class="bottom">
			<!-- nav -->
			<view class="nav">
				<view class="flex_between">
					<view class="nav_title">
						<view :class="{'active':isActive==1}" @click="chenked(1)">
							资讯动态
						</view>
					</view>
					<view class="nav_title">
						<view :class="{'active':isActive==2}" @click="chenked(2)">
							招商引流
						</view>
					</view>
				</view>
			</view>
			<!-- nav-item -->
			<view v-if="isActive==1" v-for="item, index in informationList" @click="goInfoDetails(item.informationId)">
				<view class="nav_item" v-if="item.isDisplay === '0'">
					<image class="item_img" :src="item.informationImg"></image>
					<view class="item_right">
						<view class="item_title">{{item.informationTitle}}</view>
						<view class="item_content">{{item.informationProfile}}</view>
						<view class="item_time">
							<image src="http://101.206.123.213:7051/static/image/index/时间.png"></image>
							<uni-dateformat :date="item.createTime" format="yyyy/MM/dd"></uni-dateformat>
						</view>
					</view>
				</view>
			</view>

			<view v-if="isActive==2" v-for="item, index in investmentList" @click="goInvestDetails(item.investmentId)">
				<view class="nav_item" v-if="item.isDisplay === '0'">
					<image class="item_img" :src="item.investmentImg"></image>
					<view class="item_right">
						<view class="item_title">{{item.investmentTitle}}</view>
						<view class="item_content">{{item.investmentProfile}}</view>
						<view class="item_time">
							<image src="http://101.206.123.213:7051/static/image/index/时间.png"></image>
							<uni-dateformat :date="item.createTime" format="yyyy/MM/dd"></uni-dateformat>
						</view>
					</view>
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	import {
		listNotice
	} from '@/common/js/api/notice.js';
	import {
		listBook,
		getBook
	} from '@/common/js/api/bookRecord.js';
	import {
		getVisitorRecord
	} from '@/common/js/api/visitRecord.js';

	import {
		listAdvertisement
	} from '@/common/js/api/advertisement.js';
	import {
		listInformation
	} from '@/common/js/api/information.js';
	import {
		listInvestment
	} from '@/common/js/api/investment.js';
	import {
		getStaffByOpenId
	} from '@/common/js/api/staff.js';
	import {
		getInfo
	} from '@/common/js/api/user.js'

	export default {
		data() {
			return {
				isActive: 1,
				imageBoxBottomList: ['访客登记', '预约会议室', '物业报修', '物业缴费'],
				imageBoxList: ['门禁二维码', '消息通知', '扫一扫'],
				//banner数组
				advertisementList: [],
				//资讯动态数组
				informationList: [],
				//招商引资数组
				investmentList: [],
				//消息通知数组
				noticeList: [],
				//用户基本信息
				userInfo: [],
				//当前系统时间
				date: '',
				pathList: [
					{
						name: '门禁二维码',
						//src: '../qrCode/qrCode'
						src: ''
					},
					{
						name: '消息通知',
						src: '../announcement/announcement'
					},
					{
						name: '扫一扫',
						src: ''
					},
					{
						name: '访客登记',
						src: '../registering/registering'
					},
					{
						name: '通知公告',
						src: '../announcement/announcement'
					},
					{
						name: '预约会议室',
						src: '../bookingMeetingRoom/bookingMeetingRoom'
					},
					{
						name: '物业缴费',
						src: '../propertyPayment/propertyPayment'
					},
					{
						name: '物业报修',
						src: '../propertyWarranty/propertyWarranty'
					},
				]
			}
		},
		onLoad() {
			var that = this
			//获取当前系统时间
			this.date = new Date().toISOString().slice(0, 10)
			this.userInfo = uni.getStorageSync('userInfo')
			console.log(this.userInfo);
			this.listBookRecord()
			this.listAdvertisementRecord()
			this.listInformationRecord()
			this.listInvestmentRecord()
			this.listNoticeList()
			this.getVisitorList()
		},
		onShow() {
			this.listBookRecord()
			this.listAdvertisementRecord()
			this.listInformationRecord()
			this.listInvestmentRecord()
			this.listNoticeList()
			this.getVisitorList()
		},
		methods: {
			goToContact(){
				uni.navigateTo({
					url: '../contactService/contactService'
				})
			},
			imgClick(item) {
				let urlAddress = item.url
				uni.navigateTo({
					url: '../bannerDetail/bannerDetail?urlAddress=' + urlAddress,
				})
			},
			//时间比较
			DateBiJiao(firstDate, lastDate) {
				var arr = firstDate.split("-");
				var firsttime = new Date(arr[0], arr[1], arr[2]);
				var firsttimes = firsttime.getTime();

				var arrs = lastDate.split("-");
				var lasttime = new Date(arrs[0], arrs[1], arrs[2]);
				var lasttimes = lasttime.getTime();
				if (firsttimes == lasttimes) {
					return true;
				} else
					return false;
			},
			chenked(type) {
				this.isActive = type
			},
			navigaterTo(data) {
				this.pathList.some(item => {
					if (item.name.indexOf(data) > -1) {
						if(item.src!=''){
							uni.navigateTo({
								url: item.src
							})
						}else{
							uni.showToast({
								icon: 'none',
								title: "该功能还在开发中，请使用其他功能！..."
							})
						}
					}
				})
			},
			//跳转至资讯动态信息详情界面
			goInfoDetails(informationId) {
				uni.navigateTo({
					url: "../infoDetail/infoDetail?informationId=" + informationId
				})
			},
			//跳转至招商引流详情页
			goInvestDetails(investmentId) {
				uni.navigateTo({
					url: "../infoDetail/infoDetail?investmentId=" + investmentId
				})
			},
			//获取banner图片
			listAdvertisementRecord() {
				listAdvertisement().then(res => {
					this.advertisementList = res.rows
				})
			},
			//获取资讯动态信息列表
			listInformationRecord() {
				listInformation().then(res => {
					this.informationList = res.rows
				})
			},
			//获取招商引资信息列表
			listInvestmentRecord() {
				listInvestment().then(res => {
					this.investmentList = res.rows
				})
			},
			//获取通知消息
			listNoticeList() {
				listNotice().then(res => {
					let newList = res.rows
					for (let i in newList) {
						if (this.DateBiJiao(this.date, newList[i].createTime.slice(0, 10)) && newList[i].status ==
							0) {
							this.noticeList.push(newList[i].noticeTitle)
						}
					}
				})
			},
			//获取访客预约审批情况
			getVisitorList() {
				let openId = this.userInfo.openid
				getVisitorRecord(openId).then(res => {
					let newList = res.data
					for (let i in newList) {
						if (newList[i].approverTime != null && this.DateBiJiao(this.date, newList[i].approverTime
								.slice(0,
									10)) && newList[i].approverState === '1') {
							this.noticeList.push("预约访问" + newList[i].visitComp + "审批通过")
						} else if (newList[i].approverTime != null && this.DateBiJiao(this.date, newList[i]
								.approverTime
								.slice(0, 10)) && newList[i].approverState === '2') {
							this.noticeList.push("预约访问" + newList[i].visitComp + "审批拒绝")
						}
					}
				})
			},
			//获取会议室预定审批情况
			listBookRecord() {
				let phone = this.userInfo.sysUser.phoneNumber
				if (phone != '' && phone != undefined) {
					getBook(phone).then(res => {
						let newList = res.data
						for (let i in newList) {
							if (newList[i].approverTime != null && this.DateBiJiao(this.date, newList[i]
									.approverTime
									.slice(0, 10)) && newList[i].approverState === '1') {
								this.noticeList.push("预约访问" + newList[i].broadroomName + "审批通过")
							} else if (newList[i].approverTime != null && this.DateBiJiao(this.date, newList[i]
									.approverTime
									.slice(0, 10)) && newList[i].approverState === '2') {
								this.noticeList.push("预约访问" + newList[i].broadroomName + "审批拒绝")
							}
						}
					})
				}
			},

		},
	}
</script>

<style>
	@import url("/static/font/iconfont.css");
</style>
<style lang="scss" scoped>
	.slides {
		height: 200rpx;
		width: 100%;
	}

	.sbody {
		height: 100vh;
		font-size: 24rpx;
		background: url("http://101.206.123.213:7051/static/image/index/首页背景.png");
		background-size: 100% 300upx;
		/* 第一个值为宽，第二个值为高，当设置一个值时，将其作为图片宽度来等比缩放 */
		background-repeat: no-repeat;
		background-color: white;
	}

	.notice {
		height: 96rpx;
		display: flex;

		.notice-img {
			width: 96rpx;
			display: inline-block;
			background: url(http://101.206.123.213:7051/static/image/index/小喇叭.png);
			width: 100rpx;
			height: 100%;
			background-repeat: no-repeat;
			background-size: 100% 100%;
		}

		.notice-title {
			height: 100%;
			display: inline-block;
			width: 40rpx;
			word-break: break-all;
			padding: 0 10rpx;
			font-size: 20rpx;
			color: grey;
		}

		.notic-message {
			display: flex;
			padding: 0 20rpx;
			height: 100%;
			line-height: 96rpx;
			width: calc(100% - 136rpx);
			justify-content: space-between;
		}
	}

	.top {
		.boxbody {
			width: 90%;
			margin: auto;
			height: 200upx;
			border-radius: 10px;
			background-color: white;
			box-shadow: 0px 5upx 5upx #999999;

		}

		.boxbottom {
			height: 150rpx;
		}
	}

	.image-box {
		position: relative;
		transform: translateY(50%);
	}

	.image-box-bottom {
		position: relative;
		transform: translateY(20%);
	}

	.box-image {
		display: block;
		margin: auto;
		width: 50rpx;
		height: 50rpx;
		margin-bottom: 20rpx;
	}

	.textStyle {
		display: flex;
		justify-content: space-around;
		color: black;
	}

	.bottom {
		width: 100%;
		background-color: white;

		.nav {
			.flex_between {
				display: flex;

				.nav_title {
					width: 150upx;
					margin-top: 10px;
					height: 70rpx;
					line-height: 70rpx;
					text-align: center;
					font-size: 24rpx;
					font-family: "PingFang";
					color: #999;
				}
			}
		}

		.active {
			position: relative;
			color: black;
			font-size: 28rpx;
			font-weight: bold;
		}

		.active::after {
			content: "";
			position: absolute;
			width: 40rpx;
			border-radius: 10upx;
			height: 8rpx;
			background-color: #0a73d5;
			left: 0px;
			right: 0px;
			bottom: 0px;
			margin: auto;

		}

		.nav_item {
			padding-top: 15px;
			width: 90%;
			display: flex;
			flex-direction: row;
			justify-content: center;
			background-color: white;
			margin: auto;

			image {
				width: 160px;
				height: 102px;
				border-radius: 10px;
			}

			.item_right {
				width: 210px;
				height: 102px;
				margin-left: 10px;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				align-items: center;

				.item_title {
					width: 100%;
					font-family: PingFang SC;
					font-weight: bold;
					color: #444444;
					font-size: 12px;
					overflow: hidden;
					-webkit-line-clamp: 2;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-box-orient: vertical;
				}

				.item_content {
					width: 100%;
					font-family: PingFang SC;
					color: #999999;
					font-size: 11px;
					overflow: hidden;
					-webkit-line-clamp: 2;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-box-orient: vertical;
				}

				.item_time {
					width: 100%;
					display: flex;
					flex-direction: row;
					align-items: center;
					font-family: PingFang SC;
					color: #999999;
					font-size: 11px;

					image {
						width: 14px;
						height: 14px;
						margin-right: 5px;
					}
				}
			}

		}
	}
</style>
